package com.chen.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;




/**
 * RabbitMQ配置
 * 主题（Topic）模式
 */
@Configuration
public class RabbitMQConfig {

    /**
     * 队列
     */
    private static final String QUEUE = "seckillQueue";

    /**
     * 交换机
     */
    private static final String EXCHANGE = "seckillExchange";

    /**
     * 队列bean
     * @return
     */

    @Bean
    public Queue queue(){
        return new Queue(QUEUE);
    }


    /**
     * Topic交换机可以通过* # 等路由key匹配队列
     * @return
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(EXCHANGE);
    }

    @Bean
    public Binding binding(){
        return BindingBuilder.bind(queue()).to(topicExchange()).with("seckill.#");
    }
}
